package cn.mesmile.activity.listener1;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.springframework.stereotype.Component;

/**
 * @author zb
 * @date 2021/12/23 15:47
 * @Description 监听所有任务结束
 */
@Slf4j
@Component
public class TaskCompletedListener implements ActivitiEventListener {

    @Override
    public void onEvent(ActivitiEvent event) {
        System.out.println(">>>>>>>>>>>>  任务结束进入这里");
        if (event instanceof ActivitiEntityEventImpl) {
            // 5011
            String processInstanceId = event.getProcessInstanceId();

            ActivitiEntityEventImpl eventImpl = (ActivitiEntityEventImpl) event;

            TaskEntity entity = (TaskEntity)eventImpl.getEntity();
            String assignee = entity.getAssignee();
            String taskDefinitionKey = entity.getTaskDefinitionKey();
            // 5019
            String taskId = entity.getId();

        }
    }

    /**
     * 监听异常处理策略
     * @return
     */
    @Override
    public boolean isFailOnException() {
        return false;
    }
}
